package com.kun.peng.system.mapper;

import com.kun.peng.mybatis.base.MyBaseMapper;
import com.kun.peng.system.domain.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * Created on 2021/11/17.
 *
 * @author xuebaopeng
 * Description
 */
@Mapper
public interface RoleMapper extends MyBaseMapper<Role> {

    /**
     * 根据菜单Id查询
     * @param menuIds
     * @return
     */
    @Select(value = "SELECT r.* FROM sys_role r, sys_roles_menus m WHERE " +
            "r.role_id = m.role_id AND m.menu_id in #{menuId}")
    List<Role> findInMenuId(@Param("menuId")List<Long> menuIds);

    /**
     * 根据用户ID查询
     * @param userId 用户ID
     * @return
     */
    Set<Role> findByUserId(@Param("userId")Long userId);

    /**
     * 解绑角色菜单
     * @param menuId 菜单ID
     */
    @Delete(value = "delete from sys_roles_menus where menu_id =#{menuId}")
    void untiedMenu(@Param("menuId")Long menuId);

    /**
     * 根据名称查询
     * @param name
     * @return
     */
    Role findByName(@Param("name")String name);

    /**
     * 根据角色查询
     * @param ids
     * @return
     */
    int countByRoles(@Param("ids")Set<Long> ids);

    int countByDepts(@Param("deptIds")Set<Long> deptIds);
}
